package de.karnik.dokobu.navigation;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import de.karnik.dokobu.persistence.DoKoBuUser;

public class NavGenerator {

	private NavGroup root = new NavGroup( "root" );
	
	public NavGenerator() {}
	
	public NavGroup generateNav( DoKoBuUser currentUser ) {
		
		UserService userService = UserServiceFactory.getUserService();
		
		System.out.println( userService.isUserLoggedIn() );
		//if( userService != null &&  !userService.isUserLoggedIn() )
//			return null;

		NavGroup profile = new NavGroup( "dokobu.menu.main" );
		profile.addNavElement( new NavItem( "dokobu.menu.main.home", "dokobu.menu.main.home.hint", "/app/index" ) );
		profile.addNavElement( new NavItem( "dokobu.menu.main.profile.show", "dokobu.menu.main.profile.show.hint", "/app/profile" ) );
		profile.addNavElement( new NavItem( "dokobu.menu.main.logout", "dokobu.menu.main.logout.hint", userService.createLogoutURL( "/app/index" ) ) );
		root.addNavElement( profile );
		
		NavGroup manage = new NavGroup( "dokobu.menu.manage" );
		manage.addNavElement( new NavItem( "dokobu.menu.manage.shoppinglist", "dokobu.menu.manage.shoppinglist.hint", "/app/slists" ) );
		manage.addNavElement( new NavItem( "dokobu.menu.manage.recipes", "dokobu.menu.manage.recipes.hint", "/app/recipes" ) );
		manage.addNavElement( new NavItem( "dokobu.menu.manage.ingredients", "dokobu.menu.manage.ingredients.hint", "/app/ingredients" ) );
		root.addNavElement( manage );
				
		//if( currentUser.getRole() == DoKoBuUser.ROLE_ADMIN ) {
			NavGroup administration = new NavGroup( "dokobu.menu.admin" );
			administration.addNavElement( new NavItem( "dokobu.menu.admin.users", "dokobu.menu.admin.users.hint", "/app/admin/users" ) );
			administration.addNavElement( new NavItem( "dokobu.menu.admin.commonconfig", "dokobu.menu.admin.commonconfig.hint", "/app/admin/common" ) );
			root.addNavElement( administration );
		//}
		
		return root;
	}
	
}